<template>
    <div>
        <avue-form ref="form" v-model="obj" :option="option"
                   @reset-change="emptytChange"
                   @submit="submit">
        </avue-form>
    </div>
</template>

<script>

export default {
    data() {
        return {
            obj: {},
            isIdFind: false,
        }
    },
    props: {
        closeDialog: [],
        uri: {},
        rowData: {},
    },
    // watch: {
    //     rowData: function (newRowData, oldRowData) {
    //         // console.debug("原:", oldRowData.id, "  -->新:", newRowData.id)
    //
    //     }
    // },
    computed: {
        option() {
            return {
                // size: "small",
                submitBtn: true,
                emptyBtn: true,
                detail: true,
                labelWidth: 110,
                submitText: '提交',
                emptyText: "关闭",
                column: [
                    {
                        label: '请求人',
                        prop: 'fullName',
                        maxlength: 32,
                        showWordLimit: true,
                        span: 12,
                    },
                    {
                        label: '请求端',
                        prop: 'type',
                        type: 'select',
                        dicData: this.dict.get(this.website.Dict.Base.AuthorityType),
                        span: 12,
                    },
                    {
                        label: '请求人Id ',
                        prop: 'userId',
                        maxlength: 32,
                        showWordLimit: true,
                    },
                    {
                        label: '请求来源',
                        prop: 'referer',
                        maxlength: 512,
                        showWordLimit: true,
                        span: 12,

                    },
                    {
                        label: '请求类',
                        prop: 'classDesc',
                        maxlength: 256,
                        showWordLimit: true,
                        span: 12,
                    },
                    {
                        label: '用户主机名',
                        prop: 'host',
                        maxlength: 128,
                        showWordLimit: true,
                        span: 12,
                    },
                    {
                        label: '请求方法',
                        prop: 'methodDesc',
                        maxlength: 256,
                        showWordLimit: true,
                        span: 12,
                    },
                    {
                        label: '用户真实Ip',
                        prop: 'ip',
                        maxlength: 128,
                        showWordLimit: true,
                        span: 12,
                    },
                    {
                        label: '请求uri',
                        prop: 'uri',
                        maxlength: 256,
                        showWordLimit: true,
                        span: 12,
                    },


                    {
                        label: '服务器地址',
                        prop: 'serverName',
                        maxlength: 256,
                        showWordLimit: true,
                        span: 12,
                    },
                    {
                        label: '请求url',
                        prop: 'url',
                        maxlength: 512,
                        showWordLimit: true,
                        span: 12,

                    },
                    {
                        label: '服务器端口',
                        prop: 'port',
                        maxlength: 32,
                        showWordLimit: true,
                        span: 12,
                    },
                    {
                        label: '请求方式',
                        prop: 'method',
                        maxlength: 32,
                        showWordLimit: true,
                        span: 12,
                    },
                    {
                        label: '请求包路径',
                        prop: 'packageName',
                        maxlength: 256,
                        showWordLimit: true,
                        span: 12,
                    },
                    {
                        label: '请求时间',
                        prop: 'createTime',
                        maxlength: 256,
                        showWordLimit: true,
                        span: 12,
                    },

                    {
                        label: '请求类路径',
                        prop: 'className',
                        maxlength: 256,
                        showWordLimit: true,
                        span: 12,
                    },

                    {
                        label: '请求结果',
                        prop: 'state',
                        maxlength: 9,
                        showWordLimit: true,
                        span: 24,
                    },
                    {
                        label: '请求数据',
                        prop: 'requestData',
                        type: 'textarea',
                        maxlength: 0,
                        showWordLimit: true,
                        span: 12
                    },
                    {
                        label: '返回数据',
                        prop: 'responseData',
                        type: 'textarea',
                        maxlength: 0,
                        showWordLimit: true,
                        span: 12,
                    },
                    {
                        label: '请求头',
                        prop: 'requestHeader',
                        type: 'textarea',
                        maxlength: 0,
                        showWordLimit: true,
                        span: 20
                    },
                    {
                        label: '响应总耗时',
                        prop: 'executeTime',
                        maxlength: 7766279631452241920,
                        showWordLimit: true,
                        span: 12,
                    },
                    {
                        label: '业务总耗时',
                        prop: 'businessTime',
                        maxlength: 7766279631452241920,
                        showWordLimit: true,
                        span: 12,
                    },

                ]
            }
        }
    },
    created() {
        if (this.isIdFind) {
            this.findId(this.rowData);
        } else {
            this.obj = this.rowData;
            this.obj.requestHeader = JSON.stringify(JSON.parse(this.rowData.requestHeader), null, 4);
            this.obj.requestData = JSON.stringify(JSON.parse(this.rowData.requestData), null, 4);
            this.obj.responseData = JSON.stringify(JSON.parse(this.rowData.responseData), null, 4);
        }
    },

    methods: {
        emptytChange() {
            this.$emit('closeDialog', false);
        },
        submit(form, done) {
            this.crud.put(this.uri.info + "/" + this.obj.id, this.obj).then((res) => {
                console.debug(res);
                if (res.data.code == 200) {
                    this.$emit('closeDialog', true);
                }
                done(form);
            }).catch(err => {
                console.error(err);
                done(form);
            })
        },
        findId(rowData) {
            this.crud.get(this.uri.info + "/" + rowData.id).then((res) => {
                Object.assign(this.obj, res.data.data);
            })
        }
    }
}
</script>
